package com.aki.ai_property.service.impl;

import com.aki.ai_property.dao.AfficheDao;
import com.aki.ai_property.entity.Affiche;
import com.aki.ai_property.service.intf.AfficheService;

import com.aki.ai_property.vo.PageBean;
import com.aki.ai_property.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author 34553
 * @date 2022/8/27
 */
@Service
public class AfficheServiceImpl implements AfficheService {
    @Autowired
    private AfficheDao dao;
    @Override
    public Result save(Affiche affiche) {
        if(dao.save(affiche)>0){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }

    @Override
    public Result update(Affiche affiche) {
        if(dao.update(affiche)>0){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }

    @Override
    public Result delete(int id) {
        if(dao.delete(id)>0){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }

    @Override
    public PageBean selectPage(String name, int page, int limit) {

        if(name!=null && name.length()>0){
            name="%"+name+"%";
        }
        int start=(page-1)*limit;

        return PageBean.ok(dao.selectCount(name),dao.selectPage(name,start,limit));
    }
    }